package cn.bugstack.domain.activity.service.discount.impl;

import cn.bugstack.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.bugstack.domain.activity.service.discount.AbstractDiscountCalculateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("ZK")
@Slf4j
public class ZKCalculateService extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {
        log.info("优惠策略折扣计算:{}", groupBuyDiscount.getDiscountType().getCode());
        // 获取营销表达式
        String marketExpr = groupBuyDiscount.getMarketExpr();
        String[] split = marketExpr.split(",");
        // 折扣
        BigDecimal x= new BigDecimal(split[0]);

        BigDecimal discountPrice = originalPrice.multiply(x);

        if(discountPrice.compareTo(BigDecimal.ZERO)<=0){
            return new BigDecimal("0.01");
        }
        return discountPrice;
    }
}
